package cn.tedu.api;

import java.util.Objects;

/**
 * Date：2021年10月
 * Author：程Sir
 * Name： JavaSE-API
 * Content:
 */
public class Person { // javabean对待
    int age;
    String name;
    public Person(String name,int age){
        this.age = age;
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true; // 是不是同一个
        if (o == null || getClass() != o.getClass()) return false; // 判断是null 和 判断是不是同一个类
        Person person = (Person) o; // 能够走到这一步就说明是属于同一个类
        return age == person.age &&
                Objects.equals(name, person.name);
    }


    public static void main(String[] args) {
        Person p1 = new Person("123",10);
        Person p2 = new Person("1234",20);

        System.out.println(p1.toString());
        System.out.println(p2);
        System.out.println("===============");
        System.out.println(p1==p2);// false
        System.out.println(p1.equals(p2));// true
    }
}
